package com.hl.sfzy.controller;

import com.github.pagehelper.PageInfo;
import com.hl.sfzy.entity.CourseMark;
import com.hl.sfzy.service.CourseMarkService;
import com.hl.sfzy.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/courseMark")
public class CourseMarkController {
    @Autowired
    private CourseMarkService courseMarkService;
    @PostMapping("/add")
    public R add(@RequestBody CourseMark courseMark){
        int i = courseMarkService.add(courseMark);
        if (i!=0){
            return R.ok("添加成功");
        }else {
            return R.fail("添加失败");
        }
    }
    @GetMapping("/{id}")
    public R findById(@PathVariable("id") Long id){
        CourseMark courseMark = courseMarkService.findById(id);
        return R.ok(courseMark);
    }
    @PutMapping("/edit")
    public R edit(@RequestBody CourseMark courseMark){
        int i = courseMarkService.edit(courseMark);
        if (i!=0){
            return R.ok("修改成功");
        }else {
            return R.fail("修改失败");
        }
    }
    @GetMapping("/findAll")
    public R findAll(
            @RequestParam(value = "pageNum",required = false,defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize",required = false,defaultValue = "10") Integer pageSize,
            CourseMark courseMark){
        PageInfo<CourseMark> pageInfo = courseMarkService.findAll(pageNum, pageSize, courseMark);
        return R.ok(pageInfo);
    }
    @DeleteMapping("/{id}")
    public R remove(@PathVariable("id") Long id){
        int i = courseMarkService.remove(id);
        if (i!=0){
            return R.ok("删除成功");
        }else {
            return R.fail("删除失败");
        }
    }
    @DeleteMapping("/removeBatch")
    public R removeBatch(@RequestBody List<Long> ids){
        int i = courseMarkService.removeBatch(ids);
        if (i!=0){
            return R.ok("删除成功");
        }else {
            return R.fail("删除失败");
        }
    }
}
